package com.baizhi.lqy.controller;

import com.baizhi.lqy.entity.Admin;
import com.baizhi.lqy.service.AdminServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.Map;

@Controller
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminServiceImpl adminServiceimpl;

    //验证码
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/getImageCodes")
    public Map<String,String> getimage() throws IOException {

        return adminServiceimpl.getimage();
    }

    //登录
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/login")
    public Map<String, String> login(@RequestBody Admin admin,String token){
        return adminServiceimpl.login(admin,token);
    }

    //获取登录信息
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/getUserInfo")
    public Admin getUserInfo(String token){
        return adminServiceimpl.getUserInfo(token);
    }

    //退出登录
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/logout")
    public void logOut(String token){
        adminServiceimpl.logOut(token);
    }

}
